function ajax(config={}){
	let {url,method="get",success,params={},data} = config;
	let paramsUrl = Object.keys(params).map(key=>key+"="+params[key]).join("&");
	if(paramsUrl) url+="?"+paramsUrl;
	const xhr = new XMLHttpRequest();
	xhr.open(method,url);
	if(method==="post" && data){
		// 判断data是否为对象
		if(typeof data === "object"){
			xhr.setRequestHeader("Content-Type","application/json");
			xhr.send(JSON.stringify(data));
		}else{
			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xhr.send(data);
		}
		xhr.send();
	}else{
		xhr.send();
	}
	
	xhr.onload = function(){
		success(xhr.response);
	};
}
ajax.get = function(url,config){
	this({
		url,
		...config
	})
}
ajax.post = function(url,data,config){
	this({
		url,
		method:"post",
		data,
		...config
	})
}